﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Model;
using AspNetCs.Enumerations.Channel_Enum;
using System.Data;
public partial class Users_Create_Cemetery : BasePage
{

    protected string DefaultValue = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Base_CurrPath = Base_CurrPath + " >> 会员管理中心 >> 创建新的陵园";
        CheckUserExit("Login.Aspx?ReUrl=" + Server.UrlEncode(configInfo.InstallDir + "Users/Create_Cemetery.Aspx"), "", true);
        if (!Page.IsPostBack)
        {
            int CreateNum = Memorial_Bll.CreateNew.GetDataTable("  where CreateId=" + Base_GetLoginInfo.GetUserID).Rows.Count;
            if (CreateNum >= configInfo.lygsNum)
            {
                this.Panel1.Visible = true;
                this.Panel2.Visible = false;
                DefaultValue = StringHelper.RndNum(8);
                this.Txt_Number.Text = DefaultValue;
                this.Txt_Number.ReadOnly = true;
            }
            else
            {
                this.Panel1.Visible = false;
                this.Panel2.Visible = true;
            }
            bindTemple();
            MusicBLL musicBLL = new MusicBLL();
            musicBLL.BindMusic(ddlMusic);
        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Cemetery_Model md = new Cemetery_Model();
        string Re = "";
        if (!StringHelper.Str_IsInt(Txt_Number.Text.ToString(), out Re))
        {
            ShowMsgBack("陵园馆号必须全部为数字");
            Response.End();
        }

        md.Numid = Re;
        md.Names = StringHelper.RemoveHtml(Txt_Name.Text.ToString());
        if (Request["province"] != null)
        {
            md.Province = StringHelper.isNumber_int(Request["province"].ToString());
        }
        if (md.Province > 0)
        {
            if (Request["city"] != null)
            {
                md.City = StringHelper.isNumber_int(Request["city"].ToString());
            }
        }
        if (Request["TempleID"] != null)
        {
            md.TempleId = StringHelper.isNumber_int(Request["TempleID"].ToString());
        }
        if (md.TempleId <= 0)
        {
            ShowMsgBack("请选择陵园模板!");
            Response.End();
        }

        Temple_Model temple = TempleBll.CreateNew.GetModel(md.TempleId);

        if (temple.Id <= 0)
        {
            ShowMsgBack("请选择陵园模板!");
            Response.End();
        }

        md.CreateId = Base_GetLoginInfo.GetUserID;
        md.Ischeck = 1;
        md.MusicId = StringHelper.isNumber_int(ddlMusic.SelectedValue);
        string Msg = "";
        int result = Cemetery_Bll.CreateNew.Add(md, out Msg);

        if (result > 0)
        {
            Point_Log_Model PointLogMd = new Point_Log_Model();
            PointLogMd.NetIp = StringHelper.Ip();
            PointLogMd.UserId = Base_GetLoginInfo.GetUserID;
            PointLogMd.Point = temple.Point;
            PointLogMd.Readme = "创建陵园[" + md.Numid + "]号馆,扣出点数:" + temple.Point.ToString("#.##") + "点，创建时间:" + DateTime.Now.ToShortDateString() + "";
            Point_Log_Bll.CreateNew.Add(PointLogMd);
            ResultStr("Cemetery_List.Aspx", Msg, true);
        }
        else
        {
            ShowMsgBack(Msg);
        }
        Response.End();
    }
    protected void bindTemple()
    {
        DataTable dt = TempleBll.CreateNew.GetDataTable(Channel_Type.cemetery, 0);
        this.DataList1.DataSource = dt;
        this.DataList1.DataKeyField = "id";
        this.DataList1.DataBind();
    }
    protected string IsEnabled(object currpoint)
    {
        string Re = "";
        if (Base_GetUserInfo.Point < StringHelper.isNumber_decimal(currpoint.ToString()))
        {
            Re = " disabled   style='border:0px;'";
        }

        return Re;
    }
}
